/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Merlion.MRP.entity;

import Merlion.SCM.entity.ProductEntity;
import java.util.Collection;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

@Entity
@DiscriminatorValue(value = "PWD")
public class PlannedWeeklyDemandEntity extends PlannedDemandEntity {

    int weeklyDemand;

    @OneToOne
    private WeeklyMaterialRequirementEntity materialWeeklyRequirement;
    @ManyToOne
    private PlannedMonthlyDemandEntity plannedMonthlyDemand;
    @OneToMany(mappedBy = "plannedWeeklyDemand")
    private Collection<PlannedDailyDemandEntity> plannedDailyDemandEntities;
    private boolean converted;
    private boolean decomposed;
    private int nWorkdays;

    public PlannedWeeklyDemandEntity() {
        this.converted = false;
        this.decomposed = false;
    }

    public PlannedWeeklyDemandEntity(ProductEntity product, Integer yearInt, Integer monthInt, Integer weekOfMonth) {
        String idString = "PWD-FIN" + product.getId().toString() + "Y" + yearInt.toString() + "M" + monthInt.toString() + "W" + weekOfMonth.toString();
        this.id = idString;
        this.yearInt = yearInt;
        this.monthInt = monthInt;
        this.weekOfMonth = weekOfMonth;
        this.dayOfMonth = 99;
        this.product = product;
        this.converted = false;
        this.decomposed = false;
        this.plannedDailyDemandEntities = null;
    }

    public int getWeeklyDemand() {
        return weeklyDemand;
    }

    public void setWeeklyDemand(int weeklyDemand) {
        this.weeklyDemand = weeklyDemand;
    }

    public WeeklyMaterialRequirementEntity getMaterialWeeklyRequirement() {
        return materialWeeklyRequirement;
    }

    public void setMaterialWeeklyRequirement(WeeklyMaterialRequirementEntity materialWeeklyRequirement) {
        this.materialWeeklyRequirement = materialWeeklyRequirement;
    }

    public PlannedMonthlyDemandEntity getPlannedMonthlyDemand() {
        return plannedMonthlyDemand;
    }

    public void setPlannedMonthlyDemand(PlannedMonthlyDemandEntity plannedMonthlyDemand) {
        this.plannedMonthlyDemand = plannedMonthlyDemand;
    }

    public Collection<PlannedDailyDemandEntity> getPlannedDailyDemandEntities() {
        return plannedDailyDemandEntities;
    }

    public void setPlannedDailyDemandEntities(Collection<PlannedDailyDemandEntity> plannedDailyDemandEntities) {
        this.plannedDailyDemandEntities = plannedDailyDemandEntities;
    }

    public boolean isConverted() {
        return converted;
    }

    public void setConverted(boolean converted) {
        this.converted = converted;
    }

    public boolean isDecomposed() {
        return decomposed;
    }

    public void setDecomposed(boolean decomposed) {
        this.decomposed = decomposed;
    }

    public int getnWorkdays() {
        return nWorkdays;
    }

    public void setnWorkdays(int nWorkdays) {
        this.nWorkdays = nWorkdays;
    }



    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PlannedWeeklyDemandEntity)) {
            return false;
        }
        PlannedWeeklyDemandEntity other = (PlannedWeeklyDemandEntity) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "mrp.entities.PlannedWeeklyDemandEntity[ id=" + id + " ]";
    }
}
